package com.example.demo.config;

import com.example.demo.controller.MockController;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class PayListener {

    @RabbitListener(queues = "queue.delayed")
    public void onMessage(Message message, Channel channel) throws IOException {

        System.out.println(new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
        //把已经购买设置值
        MockController.pay = true;
        log.info("已经超时");
        // 消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);

    }


}
